home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / program / vgatx10s.zip / COMDEF.H next >
C/C++ Source or Header  |  1997-04-12  |  3KB  |  76 lines

  1. /*
  2.  * This file is part of the VgaText C++ Programming Library
  3.  *
  4.  * Copyright (c) 1995, 1997 by Branislav L. Slantchev
  5.  * A fine product of Silicon Creations, Inc. (gargoyle)
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the License which accompanies this
  9.  * software. This library is distributed in the hope that it will
  10.  * be useful, but without any warranty; without even the implied
  11.  * warranty of merchantability or fitness for a particular purpose.
  12.  *
  13.  * You should have received a copy of the License along with this
  14.  * library, in the file LICENSE.DOC; if not, write to the address
  15.  * below to receive a copy via electronic mail.
  16.  *
  17.  * You can reach Branislav L. Slantchev (Silicon Creations, Inc.)
  18.  * at bslantch@cs.angelo.edu. The file SUPPORT.DOC has the current
  19.  * telephone numbers and the postal address for contacts.
  20. */
  21. #ifndef INCLUDED_COMDEF_H
  22. #define INCLUDED_COMDEF_H
  23.  
  24. #ifndef __MINMAX_DEFINED
  25. #define __MINMAX_DEFINED
  26.  
  27. template <class ClassType>
  28. inline const ClassType&
  29. min(const ClassType &a, const ClassType &b)
  30. {
  31.     return (a < b) ? a : b;
  32. }
  33.  
  34. template <class ClassType>
  35. inline const ClassType&
  36. max(const ClassType &a, const ClassType &b)
  37. {
  38.     return (a > b) ? a : b;
  39. }
  40.  
  41. #endif /* __MINMAX_DEFINED */
  42.  
  43. template <class ClassType>
  44. inline void
  45. swap(ClassType &a, ClassType &b)
  46. {
  47.     ClassType temp = a;
  48.     a = b;
  49.     b = temp;
  50. }
  51.  
  52. /*
  53.  * b i t   m a n i p u l a t i o n   f o r   i n t e g r a l   t y p e s
  54.  * ──────────────────────────────────────────────────────────────────────────
  55.  * these bit manipulation macros work with integers, chars and longs. note
  56.  * that bits are conventionally numbered from right to left, 0 to 7, 15 or 31
  57. */
  58. #define iTestBit(value, bitno)   Boolean((value) & (1L << (bitno)))
  59. #define iSetBit(value, bitno)    ( (value) |=  (1L << (bitno)) )
  60. #define iClearBit(value, bitno)  ( (value) &= ~(1L << (bitno)) )
  61. #define iToggleBit(value, bitno) ( (value) ^=  (1L << (bitno)) )
  62.  
  63. /*
  64.  * b i t   m a n i p u l a t i o n   f o r   a r r a y s
  65.  * ──────────────────────────────────────────────────────────────────────────
  66.  * these macros manipulate bits in arrays of 8-bit chars. note that the bits
  67.  * are numbered consecutively, starting from 0, up to the number of chars in
  68.  * the array * 8 - 1. (an array of 10 chars will hold 80 bits, from 0 to 79)
  69. */
  70. #define TestBit(a, bitno)       Boolean(a[(bitno)>>3] & (1<<((bitno) & 7)))
  71. #define SetBit(a, bitno)        ( a[(bitno) >> 3] |=  (1 << ((bitno) & 7)) )
  72. #define ClearBit(a, bitno)      ( a[(bitno) >> 3] &= ~(1 << ((bitno) & 7)) )
  73. #define ToggleBit(a, bitno)     ( a[(bitno) >> 3] ^=  (1 << ((bitno) & 7)) )
  74.  
  75. #endif /* INCLUDED_COMDEF_H */
  76.